﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Ledict.ConditionExtract.BLL;
using Ledict.ConditionExtract.Common;
using Ledict.ConditionExtract.Model;

namespace Ledict.ConditionExtract
{
    public partial class WB_AddKeyWords : Form
    {
        public string WB_ID = "";
        public string WBK_ID = "";
        public string WBK_Word = "";
        WordBankKeyWordsBLL wordbankkeywordsbll = new WordBankKeyWordsBLL();
        Express_WordBankRelBLL express_wordbankrelbll = new Express_WordBankRelBLL();
        NewIDBLL newid = new NewIDBLL();
        public WB_AddKeyWords()
        {
            InitializeComponent();
        }

         static WB_AddKeyWords _default;
        public static WB_AddKeyWords Default
        {
            get
            {
                if (_default == null || _default.IsDisposed)
                {
                    _default = new WB_AddKeyWords();
                }
                return _default;
            }
        }

        private void Save_Click(object sender, EventArgs e)
        {
            try
            {
                SYS_WordBank_KeyWords model = new SYS_WordBank_KeyWords();
                if (WBK_ID == "")
                {
                    string[] WordsTextArr = WordsText.Text.Split(',', '，', ';', '；');
                    foreach (var item in WordsTextArr)
                    {
                        if (item!="")
                      {
                          model.WB_ID = WB_ID;
                          model.WBK_Word = item;
                          model.WBK_Length = item.Length;
                          model.WBK_ID = newid.JudgeDoc_CreateID("SYS_WordBank_KeyWords");
                          if (!wordbankkeywordsbll.Exists(model))
                          {
                              if (wordbankkeywordsbll.Add(model))//添加
                              {  MessageBox.Show("保存成功!"); }
                             // express_wordbankrelbll.AddList_Express_WordBankRel(model.WBK_ID, model.WBK_Word);
                          }
                      }
                    }
                }
                else 
                {
                    model.WBK_ID = WBK_ID;
                    model.WBK_Word = WordsText.Text;
                    model.WBK_Length = WordsText.Text.Length;
                    if (wordbankkeywordsbll.Update(model))// 修改
                    { MessageBox.Show("保存成功!"); }
                   // express_wordbankrelbll.Delete_Express_WordBankRel(model.WBK_ID);
                   // express_wordbankrelbll.AddList_Express_WordBankRel(model.WBK_ID, model.WBK_Word);
                }
            }
            catch( Exception error )
            {
                MessageBox.Show("保存失败!");
            }
            WB_EditWBKeyWords wb_editwbkeywords =  WB_EditWBKeyWords.Default;
            wb_editwbkeywords.WB_ID = WB_ID;
            wb_editwbkeywords.ShowGV_WB_AllWords();
            this.Close();
        }

        private void Clear_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void WB_AddKeyWords_Load(object sender, EventArgs e)
        {
            if (WBK_ID != "")
                WordsText.Text = WBK_Word;
        }

      

    }
}
